  <?php
    $header = array(
	'Type'=>'',
	'Xem'=>'', 
	'Thêm'=>'', 
	'Sửa'=>'', 
	'Xóa'=>''
	);
    $config = array(
        'header_icon' => 'isw-users',
        'header_title' => 'Phân quyền thành viên [' . $user->ADM_ACCOUNT.']',
        'ID' => '-1', //Position ID
        'showEdit' => false,
        'showDelete' => false,
    );
    $data = array();
    $arr_pri = array('select', 'insert', 'update', 'delete');
    $arr_per = array('PROJECT', 'TASK', 'TODO', 'TODO_DETAIL');
//Các project tham gia
    $i = 0;
    foreach ($resources as $resource) {
        $j = 0;
        $data[$i][$j] = $resource->RES_NAME;
        $j++;
        foreach ($arr_pri as $r) {
            $check = $this->permission->check($r, $resource->RES_CODE, $user->ADM_ID);
            if ($check == 1)
                $check = ' checked="checked"';
            else
                $check = '';

            $data[$i][$j] = '<input type="checkbox" name="' . $resource->RES_ID . '[' . $r . ']" ' . $check . ' class="setpermission" per="' . $r . '" pri="' . $resource->RES_ID . '">';
            $j++;
        }
        $i++;
    }

    echo $this->atheme->table_simple($header, $data, $config);
    ?>
 
<script>
 $(document).ready(function() {
 
    $('.setpermission').click(function() {
        var per = $(this).attr("per");
        var pri = $(this).attr("pri");
        var type = "uncheck";
        if ($(this).is(':checked')) {
            type = "check";
        }
		
        jQuery.ajax({
            type: 'POST',
            url: "<?php echo admin_url(); ?>admin/privileges/<?php echo $user->ADM_ID; ?>",
            data: "code=" + per + "&level=" + pri + "&status=" + type,
            success: function(data) {
                if (data.length == 0)
                {
                    //alert(data);
                }
                else {
                }
            }
        });
    });
    });

</script>  